<script defer>
  import('https://previews.hyperfov.com/js/hyperfov-link-previews.min.js').then(() => {
    const addPreviewToLink = () => {
      // DEBUG: console
      console.log(`addPreviewToLink`);
      setPagePreviews({
        workerUrl: 'https://preview-worker.hyperfov.com',
        assignStyles: (aElt) => {
          return document.getElementById('itonnote-webpage-preview-popover').sheet;
        },
        assignPositions: (aElt) => {
          /* if (aElt.classList.contains('blocky')) return 'cursor';
          else  */ return 'below';
        },
        getLinks: () => {
          return document.querySelectorAll(`a:not([href*='localhost']):not([href^='#'])`);
        },
      });
    };

    document.fonts.ready.then(() => {
      addPreviewToLink();
      $tw.hooks.addHook('th-navigating', (e) => {
        addPreviewToLink();
        return e;
      });
    });
  });
</script>
